package br.com.news.service;

import java.util.List;

import javax.inject.Inject;
import javax.inject.Named;

import br.com.news.utils.business.exception.BusinessException;
import br.com.news.utils.business.interfaces.IAnuncioBusiness;
import br.com.news.utils.database.beans.AnuncioBean;
import br.com.news.utils.service.exception.ServiceException;
import br.com.news.utils.service.interfaces.IAnuncioService;

@Named
public class AnuncioService implements IAnuncioService{

	@Inject
	private IAnuncioBusiness anuncioBusiness;
	
	@Override
	public List<AnuncioBean> findAll() throws ServiceException {
		try {
			return anuncioBusiness.findAll();
		} catch (BusinessException e) {
			throw new ServiceException(e);
		}
	}
	
	@Override
	public void save(AnuncioBean anuncio) throws ServiceException {
		try {
			anuncioBusiness.save(anuncio);
		} catch (BusinessException e) {
			throw new ServiceException("Erro ao tentar salvar o anuncio na camada do service.",e);
		}
	}
	
	@Override
	public void update(AnuncioBean anuncio) throws ServiceException {
		try {
			anuncioBusiness.update(anuncio);
		} catch (BusinessException e) {
			throw new ServiceException("Erro ao tentar dar update o anuncio na camada do service.",e);
		}
	}
	
	
	@Override
	public List<AnuncioBean> buscaAnunciosNaoEnviados() {
		return anuncioBusiness.buscaAnunciosNaoEnviados();
	}

}
